package com.home.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.home.common.Cache;
import com.home.model.Rent;
import com.home.service.RentService;

@Controller
public class RentAction {
	@Autowired
	private RentService rentService;

	public RentService getRentService() {
		return rentService;
	}

	public void setRentService(RentService rentService) {
		this.rentService = rentService;
	}
	@RequestMapping("/admin/rent/list.do")
	public String getAll(HttpServletRequest request) {
		List<Rent> rentList = this.getRentService().getList();
		request.setAttribute("list", rentList);
		return "/admin/rent/list";
	}

	@RequestMapping("/admin/rent/save.do")
	public String getAll(Rent rent) {
		if (rent != null) {
			this.getRentService().save(rent);
		}
		Cache.getInstance().refreshRent();
		return "redirect:/admin/rent/list.do";
	}

	@RequestMapping("/admin/rent/get.do")
	public String getAll(Integer id, HttpServletRequest request) {
		if (id != null) {
			Rent rent = this.getRentService().getRent(id);
			request.setAttribute("obj", rent);
		}
		return "/admin/rent/obj";
	}
	
	
	@RequestMapping("/admin/rent/delete.do")
	public String delete(Integer id, HttpServletRequest request) {
		if (id != null) {
			Rent rent=new Rent();
			rent.setId(id);
			this.getRentService().delete(rent);
		}
		return "redirect:/admin/rent/list.do";
	}
}
